`timescale  1ns / 1ps

module tb_udp_fdma_ddr();

// eg4d_sram_fdma_test Parameters
parameter PERIOD                = 40         ;
parameter UDP_CLK_PERIOD        = 16          ;
parameter HDMI_CLK_PERIOD       = 40         ;
parameter TEST_MEM_SIZE         = 32'd640*480;
parameter TEST_MEN_ADDR_OFFSET  = 16'd0      ;
parameter FDMA_BURST_LEN        = 16'd512    ;
parameter TOTAL_PIX             = 'd640*'d480*'d3;

// eg4d_sram_fdma_test Inputs
reg   i_clk                                = 1 ;
reg   i_rst_n                              = 0 ;
reg   udp_clk                              = 1 ;
reg   udp_data_valid                       = 0 ;
reg   [7 : 0]  udp_data                    = 0 ;
reg   hdmi_clk                             = 1 ;

// eg4d_sram_fdma_test Outputs
wire  o_fdma_clk                           ;
wire  O_led1                               ;
wire  O_led2                               ;


initial
begin
    forever #(PERIOD/2)  i_clk=~i_clk;
end

initial begin
    forever #(UDP_CLK_PERIOD / 2) udp_clk=~udp_clk;
end

initial begin
    forever #(HDMI_CLK_PERIOD / 2) hdmi_clk = ~hdmi_clk;
end

initial
begin
    repeat(50) @(posedge i_clk) i_rst_n  =  1;
end

integer i;
reg [7 : 0] mem [TOTAL_PIX - 1 : 0];
initial begin
    $readmemh("D:/University/Xilinx_A7200T_New/proj/user/src/IMAGE_PROCESS_ALGO/NOISE_FILTER/MATLAB/gauss_filter_tb_data_sct.txt", mem);
    repeat (112500) @(posedge udp_clk);
    forever begin
        udp_data_valid <= 1'b1;
        for (i = 0 ; i < TOTAL_PIX ; i = i + 1) begin    
            udp_data <= mem[i];
            @(posedge udp_clk);
        end
        udp_data_valid <= 1'b0;
        repeat (50) @(posedge udp_clk);
        // udp_data_valid <= 1'b1;
        // for (i = 0 ; i < TOTAL_PIX ; i = i + 1) begin
        //     udp_data <= mem[i];
        //     @(posedge udp_clk);
        // end
        // udp_data_valid <= 1'b0;
    end
    $finish;
end

// reg error = 0;
// integer j = 0;
// reg [7 : 0] mem_out [TOTAL_PIX - 1 : 0];
// initial begin
//     $readmemh("D:/University/Xilinx_A7200T_New/proj/user/src/IMAGE_PROCESS_ALGO/NOISE_FILTER/MATLAB/gauss_filter_tb_res_sct.txt", mem_out);
//     for (j = 0 ; j < TOTAL_PIX ; j = j + 1) begin
//         @(posedge data_out_valid);
//         @(negedge i_clk);
//         if (mem_out[j] != data_out) begin
//             error <= 1'b1;
//             $display("Error at pixel %d %d %d", j, mem_out[j], data_out);
//             $stop;
//         end 
//     end
//     repeat (50) @(posedge i_clk);
//     for (j = 0 ; j < TOTAL_PIX ; j = j + 1) begin
//         @(posedge data_out_valid);
//         @(negedge i_clk);
//         if (mem_out[j] != data_out) begin
//             error <= 1'b1;
//             $display("Error at pixel %d %d %d", j, mem_out[j], data_out);
//             $stop;
//         end 
//     end
//     $finish;
// end

eg4d_sram_fdma_test #(
    .TEST_MEM_SIZE        ( TEST_MEM_SIZE        ),
    .TEST_MEN_ADDR_OFFSET ( TEST_MEN_ADDR_OFFSET ),
    .FDMA_BURST_LEN       ( FDMA_BURST_LEN       ))
u_eg4d_sram_fdma_test (
    .i_clk                   ( i_clk                   ),
    .i_rst_n                 ( i_rst_n                 ),
    .udp_clk                 ( udp_clk                 ),
    .udp_data_valid          ( udp_data_valid          ),
    .udp_data                ( udp_data        [7 : 0] ),
    .hdmi_clk                ( hdmi_clk                ),

    .o_fdma_clk              ( o_fdma_clk              ),
    .O_led1                  ( O_led1                  ),
    .O_led2                  ( O_led2                  )
);


endmodule